package com.youlin.aop;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.time.LocalTime;
import java.util.concurrent.TimeUnit;

@Service
public class ScheduledService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    @Autowired
    private AsyncService asyncService;

    @Scheduled(cron = "0 0 2 * * ?")
    public void resetRBloomFilterScheduled() {
        if (! redisTemplate.opsForValue().setIfAbsent("resetRBloomFilterScheduled", LocalTime.now())) {
            asyncService.resetRBloomFilter();
            redisTemplate.expire("resetRBloomFilterScheduled", 1234, TimeUnit.SECONDS);
        }
    }

}
